<?php

namespace common\widgets\ajaxbtn;

use yii\base\Widget;


/**
 * @example AjaxBtn::widget()
 * @example AjaxBtn::widget(['btnclass'=>'btn btn-primary btn-block btn-main','label'=>'立即预约'])
 * @author Administrator
 */
class AjaxBtn extends Widget{
    
    public $label = '确定';  //按钮文字，默认为“确定”
    public $btnclass = 'ajaxbtn';  //按钮样式，默认“.ajaxbtn”
    public $autosubmit = true;  //点击ENTER，自动提交
    
    public function init(){
        parent::init();
        AjaxAsset::register($this->view);
    }
    
    public function run(){
        
        $idStr = '';
        if($this->autosubmit){
            $idStr = 'id="submit_btn"';
        }
        
        $csrf = \Yii::$app->request->csrfToken;
        $str = '<input type="hidden" name="_csrf" value="'.$csrf.'" />';
        $str .= '<a '.$idStr.' class="'.$this->btnclass.'" href="javascript:;" onclick="doSubmitForm(this)">'.$this->label.'</a>';
        return $str;
    }
    

}